/**
 * ReportGear(2011)
 */
package com.reportgear.core.swing.util;

import java.awt.Color;

/**
 * 
 * 
 * @version 1.0 2011-4-14
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ColorUtils {
	// Color转换为16进制显示
	public static String toHexEncoding(Color color) {
		String R, G, B;
		StringBuffer sb = new StringBuffer();
		R = Integer.toHexString(color.getRed());
		G = Integer.toHexString(color.getGreen());
		B = Integer.toHexString(color.getBlue());
		R = R.length() == 1 ? "0" + R : R;
		G = G.length() == 1 ? "0" + G : G;
		B = B.length() == 1 ? "0" + B : B;

		sb.append(R);
		sb.append(G);
		sb.append(B);

		return sb.toString();

	}

	// 把字符串表达的颜色值转换成java.awt.Color
	public static Color parseToColor(final String c) {
		Color convertedColor = Color.BLACK;
		try {
			convertedColor = new Color(Integer.parseInt(c, 16));
		} catch (NumberFormatException e) {
			e.printStackTrace();
			// codes to deal with this exception
		}

		return convertedColor;
	}
}
